package com.wclass.controller.app;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.wclass.common.ReturnObject;
import com.wclass.entity.UserWithdrawBill;
import com.wclass.interceptor.BaseContextHandler;
import com.wclass.service.IUserAmountBillService;
import com.wclass.service.IUserWithdrawBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 提现流水 前端控制器
 * </p>
 *
 * @author 张浩高
 * @since 2018-12-21
 */

@Api(description = "提现")
@RestController
@RequestMapping("/userWithdrawBill")
public class UserWithdrawBillController {

    @Autowired
    private IUserAmountBillService iUserAmountBillService;
    @Autowired
    private IUserWithdrawBillService iUserWithdrawBillService;
    /**
     * 银行卡提现
     *
     * @param amount
     * @param cardholder
     * @param bankName
     * @param bankNo
     * @return
     */
    @ApiOperation("银行卡提现")
    @RequestMapping(value = "/withdrawalApplication", method = RequestMethod.POST)
    public ReturnObject<UserWithdrawBill> withdrawalApplication(@ApiParam("提现金额") @RequestParam Long amount,
                                                                @ApiParam("持卡姓名") @RequestParam String cardholder,
                                                                @ApiParam("银行") @RequestParam String bankName,
                                                                @ApiParam("银行卡卡号") @RequestParam String bankNo) {
        return iUserAmountBillService.withdrawalApply(BaseContextHandler.getUserID(), amount, cardholder, bankName,
                bankNo);
    }

    @ApiOperation("提现记录")
    @RequestMapping(value = "/getWithdrawalApplicationBill", method = RequestMethod.POST)
    public ReturnObject<List<UserWithdrawBill>> getWithdrawalApplicationBill(@ApiParam("每页条数") @RequestParam(defaultValue = "10") int limit,
                                                                             @ApiParam("页数") @RequestParam(defaultValue = "1") int offset) {
        EntityWrapper<UserWithdrawBill> ew = new EntityWrapper<>();
        ew.eq("user_id", BaseContextHandler.getUserID());
        Page<UserWithdrawBill> obj = iUserWithdrawBillService.selectPage(new Page<>(offset, limit), ew);
        return new ReturnObject<>(0, "获取成功", obj.getTotal(), obj.getPages(), obj.getRecords());
    }
}

